﻿package mortal.game.view.battlefield
{
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.rules.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.vip.panel.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class BattlefieldEnterWindowNew extends ActivityBaseWindow
    {
        private var _vcRewardItem:Vector.<BaseItem>;
        private var _btnHonerShop:GButton;
        private var _leftTime:SecTimerView;
        private static var _instance:BattlefieldEnterWindowNew;

        public function BattlefieldEnterWindowNew(param1:ILayer = null, param2:String = "", param3:String = "")
        {
            this._vcRewardItem = new Vector.<BaseItem>;
            setSize(696, 412);
            super(param1, ImagesConst.BattlefieldTitle, ImagesConst.BattleFieldEnterBgNew);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_5:int = 0;
            var _loc_6:BaseItem = null;
            super.createDisposedChildrenImpl();
            var _loc_1:* = UICompomentPool.getUICompoment(VipOpenTipsPanel);
            _loc_1.move(225, 262);
            var _loc_2:int = 32;
            _loc_1.resetLevelTextPos(36, 9, 36, 9);
            _loc_1.resetValueTextPos(114, 9, 114, 9);
            _loc_1.bgUrl = ImagesConst.vipOpenTipsBg_mid;
            _loc_1.valueType = VipOpenTipsPanel.numberValue;
            _loc_1.vipType = EVipRecordType._EVipRecordTypeBattlehonour;
            this.addChild(_loc_1);
            pushUIToDisposeVec(_loc_1);
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(11302), 104, 380, 200, 22, this, GlobalStyle.textFormatHuang2.setSize(13)));
            this._leftTime = UIFactory.secTimeView(Language.getString(11303), 465, 380, 220, 20, this, GlobalStyle.textFormatHong.setSize(13));
            var _loc_3:Number = 172;
            var _loc_4:Number = 314;
            _loc_5 = 0;
            while (_loc_5 < 8)
            {
                
                _loc_6 = UIFactory.getUICompoment(BaseItem, _loc_3 + 44 * _loc_5, _loc_4, this._contentTopOf3DSprite);
                _loc_6.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
                this._vcRewardItem.push(_loc_6);
                _loc_5++;
            }
            this._btnHonerShop = UIFactory.gButton(Language.getString(11304), 530, 319, 65, 22, this._contentTopOf3DSprite, "GreenLinkButton");
            this._btnHonerShop.configEventListener(MouseEvent.CLICK, this.onClickHonorShop);
            this.updateIsOpen(false);
            this.updateHonorShopItems();
            return;
        }// end function

        protected function updateHonorShopItems() : void
        {
            var _loc_1:* = ShopConfig.instance.getShopSellItemByShopCode(ShopType.Honor);
            var _loc_2:* = Math.min(8, _loc_1.length);
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2)
            {
                
                this._vcRewardItem[_loc_3].itemCode = _loc_1[_loc_3].itemCode;
                _loc_3++;
            }
            return;
        }// end function

        public function updateBeginDt(param1:Date) : void
        {
            var _loc_2:* = (param1.time - ClockManager.instance.nowDate.time) / 1000;
            if (_loc_2 > 0)
            {
                this.updateIsOpen(false);
                this._leftTime.timeOutHandler = this.battleBegin;
                this._leftTime.setLeftTime(_loc_2);
            }
            else
            {
                this.updateIsOpen(true);
            }
            return;
        }// end function

        protected function battleBegin() : void
        {
            this.updateIsOpen(true);
            return;
        }// end function

        public function updateIsOpen(param1:Boolean = false) : void
        {
            if (this.isDisposed)
            {
                return;
            }
            if (param1)
            {
                this._leftTime.visible = false;
            }
            else
            {
                this._leftTime.visible = true;
            }
            return;
        }// end function

        override protected function onClickEnterBtn(event:MouseEvent) : void
        {
            if (Cache.instance.battlefieldCache.isOpen)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.BattlefieldRequestFastEnter));
            }
            else
            {
                MsgManager.showRollTipsMsg(Language.getString(11305));
            }
            return;
        }// end function

        private function onClickHonorShop(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.NPC_OpenNpcShop, ShopType.Honor));
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._btnHonerShop.dispose(param1);
            this._btnHonerShop = null;
            this._leftTime.dispose(param1);
            this._leftTime = null;
            var _loc_2:int = 0;
            while (_loc_2 < this._vcRewardItem.length)
            {
                
                this._vcRewardItem[_loc_2].dispose(param1);
                _loc_2++;
            }
            this._vcRewardItem.length = 0;
            super.disposeImpl(param1);
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show();
            return;
        }// end function

        public static function get instance() : BattlefieldEnterWindowNew
        {
            if (!_instance)
            {
                _instance = new BattlefieldEnterWindowNew;
            }
            return _instance;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
